<?php require_once('../Connections/locale.php'); ?>
<?php
mysql_select_db($database_locale, $locale);
$query_riviste = "SELECT * FROM riviste";
$riviste = mysql_query($query_riviste, $locale) or die(mysql_error());
$row_riviste = mysql_fetch_assoc($riviste);
$totalRows_riviste = mysql_num_rows($riviste);

mysql_select_db($database_locale, $locale);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>
<fieldset>
<legend>Elenco Riviste</legend>
<table border="1" id="datatable">
  <tr>
    <td><div align="center"><strong>ID</strong></div></td>
    <td><div align="center"><strong>Descrizione</strong></div></td>
    <td><strong>Uscite</strong></td>
    <td><div align="center"><strong>Costo</strong></div></td>
    <td><div align="center"><strong><a href="inserimento_rivista.php"><img src="../images/page.gif" alt="Nuova Rivista" width="18" height="18" border="0"></a></strong></div></td>
    <td><div align="center"></div></td>
  </tr>
  <?php do { ?>
  <tr>
    <td><?php echo $row_riviste['id_rivista']; ?></td>
    <td><?php echo $row_riviste['descrizione']; ?></td>
    <td><?php echo $row_riviste['n_uscite_annuali']; ?></td>
    <td><?php echo $row_riviste['costo']; ?></td>
    <td><a href="modifica_rivista.php?id_rivista=<?php echo $row_riviste['id_rivista']; ?>"><img src="../images/modifica.png" width="16" height="16" border="0"></a></td>
    <td><?php 
	
	$query_legami_abbonamenti = "SELECT * FROM abbonati_riviste WHERE id_rivista =".$row_riviste['id_rivista'];
	$legami_abbonamenti = mysql_query($query_legami_abbonamenti, $locale) or die(mysql_error());
	$row_legami_abbonamenti = mysql_fetch_assoc($legami_abbonamenti);
	$totalRows_legami_abbonamenti = mysql_num_rows($legami_abbonamenti);
	
	if ($totalRows_legami_abbonamenti == 0) { // Show if recordset empty ?>
        <img src="../images/elimina.png" width="16" height="16">
        <?php } // Show if recordset empty ?></td>
  </tr>
  <?php } while ($row_riviste = mysql_fetch_assoc($riviste)); ?>
</table>
</fieldset>
</body>
</html>
<?php
mysql_free_result($riviste);

mysql_free_result($legami_abbonamenti);
?>
